<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="renderer" content="webkit" />
<title>无标题文档</title>
<link href="__PUBLIC__/admin/sncss/css/style.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/admin/sncss/css/combo.select.css" rel="stylesheet" type="text/css" />
</head>

<body>

	<div class="place">
	<span>位置：</span>
	<ul class="placeul">
	<li><a>首页</a></li>
	<li><a>订单管理</a></li>
	<li><a>编辑订单</a></li>
	</ul>
	</div>

	<div class="formbody">

	<div class="formtitle"><span>编辑订单</span></div>
<form id="formid" name="form1" method="post" action="{:U('/Home/Order/add_order')}" onsubmit="return form1_submit();">
	<input name="oid" id="oid" type="hidden" value="<?php echo $orderdata['id'];?>" />
	<ul class="forminfo">

	<li>
	<div style="width: 86px;line-height: 34px;display: block;float: left;">自媒体</div>
	<div class="dowebok" style="float: left;">
	<select name="media" id="media" >
		<option value="<?php echo $orderdata['mid'];?>" selected><?php echo $orderdata['mname'];?></option>
	</select>
	</div>
	</li>
	<li>
	<div style="width: 86px;line-height: 34px;display: block;float: left;">专辑</div>
	<div class="dowebok" style="float: left;">
	<select name="special" id="special" >
		<option value="0" <?php if($orderdata['specialname'] == 0){echo "selected";}?>>不选择专辑</option>
		<?php foreach ($specialdata as $key => $value) { ?>
		<option value="<?php echo $value['id'];?>" <?php if($orderdata['special'] == $value['id']){echo "selected";}?>><?php echo $value['specialname'];?></option>
		<?php }?>
	</select>
	</div>
	</li>
	<li>
	<div style="width: 86px;line-height: 34px;display: block;float: left;">类型</div>
	<div class="dowebok" style="float: left;">
	<select name="label" id="label" >
		<option value="">请选择</option>
		<?php foreach ($labeldata as $key => $value) { ?>
		<option value="<?php echo $value['label_name'];?>" <?php if($orderdata['texttype'] == $value['label_name']){echo "selected";}?>><?php echo $value['label_name'];?></option>
		<?php }?>
	</select>
	</div>
	</li>
	<li><label>性别</label>
    <label><input name="sex" type="radio" value="0" <?php if($orderdata['sex'] == 0){echo "checked";}?>/>全部</label>
    <label><input name="sex" type="radio" value="1" <?php if($orderdata['sex'] == 1){echo "checked";}?> />男</label>
    <label><input name="sex" type="radio" value="2" <?php if($orderdata['sex'] == 2){echo "checked";}?> />女</label>
  </li>
	<li><label>链接</label><input name="user_url" id="user_url" type="text" class="lginput" value="" />
	<input type="button" id="get_url" class="btn" value="获取"/></li>
	<li><label>标题</label><input name="title" id="title" type="text" class="lginput" value="<?php echo $orderdata['title'];?>" /><i></i></li>
	<li><label>文章</label><textarea style="float: left;" name="article" id="article" onkeyup="cal_words()">{$articledata['article']}</textarea><i></i></li>
	<li><br><label style="width: 120px;">总字数<i id="num">0</i>个</label><label style="width: 120px;">预计用时<i id="ptime">0</i>分</label>
	<!-- <label>主播等级</label><label><input name="user_type" id="user_type" type="checkbox" value="收藏主播" />收藏主播</label> -->
	<label style="width: 160px;">等级：<select name="level" id="level" class="newselect" onchange="change_level()" >
		<?php foreach ($leveldata as $key => $value) { ?>
		<option value="<?php echo $value['id'];?>"><?php echo $value['message'];?></option>
		<?php }?>
	</select>级</label>
	<label style="width: 220px;">预计花费<i id="cost">0</i>元<i id="discount_message"></i></label>
	</li>

	<input name="wordnumber" id="wordnumber" type="hidden" value="" />
	<input name="plan_time" id="plan_time" type="hidden" value="" />
	<input name="moneynumber" id="moneynumber" type="hidden" value="" /><!-- 原价 -->
	<input name="discount" id="discount" type="hidden" value="100" /><!-- 折扣 -->
	<input name="usemoney" id="usemoney" type="hidden" value="" /><!-- 实价 -->
	<?php foreach ($leveldata as $key => $value) { ?>
	<input id="use_money<?php echo $value['id'];?>" type="hidden" value="<?php echo $value['money'];?>" />
	<?php }?>
	<input id="use_money0" type="hidden" value="0" />
	<input id="is_collect" type="hidden" value="0" name="is_collect" />
	<input id="isvip" type="hidden" value="0" name="isvip" />
	<li></li>

	<li><label>&nbsp;</label><input type="submit" class="btn" value="重新下单"/></li>
	</ul>
</form>

	</div>


</body>
<script src="__PUBLIC__/admin/Js/jquery-1.7.2.min.js"></script>
<script src="__PUBLIC__/layer/layer.js"></script>
<script src="__PUBLIC__/admin/Js/jquery.combo.select.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
var editor = UE.getEditor('article',{    //content为要编辑的textarea的id
	initialFrameWidth: 800,   //初始化宽度
	initialFrameHeight: 200,   //初始化高度
});
editor.addListener('keyup',function(){
		cal_words();
 })
</script>
<script>
$(function() {
	$('#media').comboSelect();
	$('#label').comboSelect();
	$('#special').comboSelect();
});
</script>
<script type="text/javascript">
function form1_submit(){

	var media= $('#media').val();
	if(media.length == 0){
		layer.tips('请选择自媒体', '#media');return false;
	}
	var label= $('#label').val();
	if(label.length == 0){
		layer.tips('请选择类型', '#label');return false;
	}
	var title= $('#title').val();
	if(title.length == 0){
		layer.tips('请填写标题', '#title');return false;
	}
	var article = UE.getEditor('article').getContentTxt();
	if(article.length == 0){
		layer.tips('请录入文章', '#article');return false;
	}
	var level=$('#level').val();
	if(level.length == 0){
		layer.tips('请选择等级', '#level');return false;
	}

}
//用word方式计算正文字数
function fnGetCpmisWords(str){
	sLen = 0;
	try{
		//先将回车换行符做特殊处理
		str = str.replace(/(\r\n+|\s+|　+)/g,"龘");
		//处理英文字符数字，连续字母、数字、英文符号视为一个单词
		str = str.replace(/[\x00-\xff]/,"m");
		//每个字母、数字、英文符号视为一个单词
		// str = str.replace(/[\x00-\xff]/g,"m");
		//合并字符m，连续字母、数字、英文符号视为一个单词
		str = str.replace(/m+/g,"*");
		//去掉回车换行符
		str = str.replace(/龘+/g,"");
		//返回字数
		sLen = str.length;
	}catch(e){

	}
	return sLen;
}
function change_level(){
	var last = $("#level").find("option:selected").text();
	if (last == "收藏主播") {
		$('#is_collect').val(1);
	}else{
		$('#is_collect').val(0);
	}
	cal_words();
}
function cal_words(){
var ue = UE.getEditor('article');
//获取html内容
// var html = ue.getContent();
//获取纯文本内容
var text = ue.getContentTxt();
	var max_mun = 100;//字数设置，上线时改成100
	// var article= $('#article').val();
	var length = fnGetCpmisWords(text);
	// alert(length);
	document.getElementById("num").innerHTML = length;
	document.getElementById("wordnumber").value = length;
	var discount=$('#discount').val();
	var level=$('#level').val();
	var levelmoney=$('#use_money'+level).val();
	if (length < max_mun) {
	document.getElementById("cost").innerHTML = Number(levelmoney*discount/100).toFixed(2);
	document.getElementById("moneynumber").value = Number(levelmoney).toFixed(2);
	document.getElementById("usemoney").value = Number(levelmoney*discount/100).toFixed(2);
	// alert(levelmoney);
	}else{
	var user_num = Math.round(length/max_mun);
	document.getElementById("cost").innerHTML = Number(levelmoney*user_num*discount/100).toFixed(2);
	document.getElementById("moneynumber").value = Number(levelmoney*user_num).toFixed(2);
	document.getElementById("usemoney").value = Number(levelmoney*user_num*discount/100).toFixed(2);

	}
	var plantime = Math.ceil(length/max_mun);
	document.getElementById("ptime").innerHTML = Number(plantime*15);
	document.getElementById("plan_time").value = Number(plantime*15);
	/*暂时写死每千字15分钟*/
}

//然后提交
</script>
<script type="text/javascript">
	$(window).load(function(){
		var media_id = $('#media').val();
		// alert(media_id);return false;
		mediainfo(media_id);
	});
	function mediainfo(media_id){
			// alert(media_id);
		$.get("/Home/Order/media_ajax",{media_id:media_id},function(data){
			$("#level_option").remove();
			if(data.media.uuid != 0){
				$('#use_money0').val(data.member.level_money);
				var txt = '<option id="level_option" value="'+data.member.level_id+'">收藏主播</option>';
				$("#level").append(txt);
			}else{
				$('#use_money0').val("0");
			}
			document.getElementById("discount").value = Number(100);
			if (data.media.discount_type == 0) {
				document.getElementById("discount_message").innerHTML = "(无折扣)";
			}
			if (data.media.discount_type == 1) {
				document.getElementById("discount_message").innerHTML = "(折扣未开始)";
			}
			if (data.media.discount_type == 2) {
				document.getElementById("discount_message").innerHTML = "(折扣已结束)";
			}
			if (data.media.discount_type == 3) {
				document.getElementById("discount").value = Number(data.media.discount);
				document.getElementById("discount_message").innerHTML = "("+Number(data.media.discount/10).toFixed(1)+"折)";
			}
			document.getElementById("isvip").value = data.media.isvip;
			cal_words();
		},'json');
	}
</script>
<script type="text/javascript">
	$(document).ready(function(){
		$('#get_url').click(function(){
			var user_url = $('#user_url').val();
			$.post("/Home/Order/getwebcontent",{user_url:user_url},function(data){
				// alert(data.title);
				$('#title').val(data.title);
        UE.getEditor('article').setContent(data.message);
				cal_words();
			},'json');
		});
	});
</script>
</html>
